home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / kcl / akcl / akcl1615.lha / h / 386.h next >
C/C++ Source or Header  |  1991-07-13  |  2KB  |  90 lines

  1.  
  2. #ifdef __GNUC__
  3. /* so have assembler macros */
  4. /* Normally gcc for the 386 only allows 4 operands to an asm,
  5. however we need 5 for divul.    You can easily make gcc accept
  6. more by changing one line in genconfig.c and then recompiling gcc
  7.  
  8.   printf ("\n#define MAX_RECOG_OPERANDS %d\n", max_recog_operands_flag + 3);
  9.  
  10. */  
  11. /* divul
  12.    rem=hl; f=divul(x,y,rem);
  13.          then
  14.    hl:x == f*y + rem  is true */
  15.  
  16. #define divul(x,y,hiremainder) \
  17. ({ulong __x =(x),__y=(y); \
  18.   asm volatile("divl %3" \
  19.      :"=a" (__x),"=d" (hiremainder) \
  20.      :"0" (__x),"rm"(__y),"1" (hiremainder) );  \
  21.    __x;})
  22.  
  23.  
  24. /*    mulul is a macro:
  25.     f = mulul(a,b,h) <--> h:f  == a*b
  26. */
  27.  
  28. #define mulul(x,y,hiremainder) \
  29. ({ulong __x =(x),__y=(y); \
  30.   asm volatile("mull %3" \
  31.      :"=a" (__x),"=d" (hiremainder) \
  32.      :"0" (__x),"rm"(__y));  \
  33.    __x;})
  34.  
  35.  
  36.   /* add_carry: add X and Y  adding 1 to H if there was overflow
  37.      H is presumed to be small enough not to overflow 
  38.      */
  39.  
  40. #define add_carry(x,y,h) \
  41. ({ulong __res ; \
  42.      asm volatile("addl %4,%1\n\tadcl $0,%0" \
  43.   :"=rm,rm" (h),"=r,m" (__res): "0,0" (h),"1,1" (x),"rmn,r"(y)); \
  44.     __res;})
  45.  
  46.  
  47.   /* SET_MACHINE_CARRYSet the machine carry flag
  48.      if  overflow = 1 other wise clear it.
  49.    */
  50.  
  51. #define SET_MACHINE_CARRY(overflow) \
  52.   asm volatile("addl $-1,%0" : "=r" (overflow) : "0" (overflow))
  53.  
  54.  
  55.   /* SET_OVERFLOW Set the overflow = the current carry code
  56.      Note that machine loads and mov's should not affect
  57.      the carry code. 
  58.    */
  59.  
  60. #define SET_OVERFLOW \
  61.   asm volatile("movl $0,%0\n\tadcl $0,%0" \
  62.   : "=rm" (overflow))
  63.  
  64. /* x - y */
  65. #define SUBXCC(xp,yp)\
  66. ({unsigned long _res;  asm volatile("sbbl %2,%0" \
  67.   :"=r,rm" (_res): "0,0" (xp) , "rm,r" (yp)); _res;})
  68.  
  69. #define ADDXCC(xp,yp)\
  70. ({unsigned long _res;  asm volatile("adcl %2,%0" \
  71.   :"=r,m" (_res): "0,0" (xp) , "rm,r" (yp)); _res;})
  72.  
  73. /* index of the first non zero bit numbering from left */
  74. /* don't think there is an instruction.
  75. #define bfffo(x) \
  76. ({ulong _res;  asm ("bfffo %1{#0:#0},%0" : "=r" (_res): "rm" (x)); _res;})
  77. */
  78.  
  79. #define NEED_MULUL3
  80. #define NEED_DIVUL3
  81.      
  82. #else  /* not gcc */
  83.  
  84. #endif
  85.      
  86.  
  87.  
  88.   
  89. #define BASE_COUNTER 0
  90.